﻿using EditoneLib;
using EditoneLib.Streams;
using NAudio.Wave;
using NAudio.Win8.Wave.WaveOutputs;
using Windows.Storage;

namespace EditoneLibRT
{
    internal class OutFileWriter
    {
        public static void Export(StorageFile file, ProjectStream stream)
        {
            var provider = new RawSourceWaveStream(
                stream,
                WaveFormat.CreateIeeeFloatWaveFormat(Settings.SampleRate, stream.Mapping.NumChannels)
                );

            if (file.FileType == ".wav")
            {
                WaveFileWriter.CreateWaveFile(
                    file,
                    provider
                    );
            }
            else
            {
                if (file.FileType == ".mp3")
                {
                    MediaFoundationEncoder.EncodeToMp3(provider, file);
                }
                else if (file.FileType == ".asf" || file.FileType == ".wma")
                {
                    MediaFoundationEncoder.EncodeToWma(provider, file);
                }
            }
        }
    }
}